using Luban.Defs;
using Luban.Erlang.TypeVisitors;
using Luban.Types;
using Luban.Utils;
using Scriban.Runtime;

namespace Luban.Erlang.TemplateExtensions;

public class ErlangCommonTemplateExtension : ScriptObject
{
    
    public static string ErlangSnake(string fullName)
    {
        return TypeUtil.ToErlangSnakeCase(fullName.Replace(".", ""));
    }
    
    public static string ErlangMacro(string fullName)
    {
        return TypeUtil.ToErlangMacro(fullName.Replace(".", "_"));
    }
    
    public static string ErlangPascal(string fullName)
    {
        return TypeUtil.ToErlangPascalCase(fullName.Replace(".", ""));
    }
    
    public static int FieldsLength(List<DefField> fields)
    {
        return fields.Count;
    }
    
    public static string ErlangAnnotation(string comment)
    {
        string[] lines = comment.Split(new[] { "\n" }, StringSplitOptions.None);
        return string.Join("\n", lines.Select(line => $"% {line}"));
    }
    
    
}
